/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;
import net.iwsh.core.utils.IDGenerator;

import com.us.usws.model.domain.box.BoxTheme;
import com.us.usws.model.flat.box.DOBoxTheme;

/**
 * DAO class
 * @author robot
 */
public class BoxThemeDAO {

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from box_theme";

	private static final String SQL_GET_ALL_BOXTHEMES = "select * from box_theme";

	private static final String SQL_GET_BOXTHEME_BY_PK = "select * from box_theme where uid = ?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_BOXTHEME = "insert into box_theme(uid,name,theme_picture,theme_music,bg_index,bg_detail,bg_pannel,pictures,recommend_type_dsid,channel_uid,ep_channel_ui_dsid,is_ads,end_date,description) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

	private static final String SQL_UPDATE_BOXTHEME = "update box_theme set name=?, theme_picture=?, theme_music=?, bg_index=?, bg_detail=?, bg_pannel=?, pictures=?, recommend_type_dsid=?, channel_uid=?, ep_channel_ui_dsid=?, is_ads=?, end_date=?, description=? where uid=?";

	private static final String SQL_DEL_BOXTHEME = "delete from box_theme where uid=?";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<BoxTheme> getAllBoxThemes() {
		return dbe.list(SQL_GET_ALL_BOXTHEMES, BoxTheme.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<BoxTheme> getBoxThemes(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_BOXTHEMES, null, start, end);
		return dbe.list(swp.getSql(), BoxTheme.class, swp.getParams());
	}

	/**
	 * Get BoxTheme by primary key.
	 */
	public BoxTheme getBoxTheme(String uid) {
		BoxTheme b = dbe.load(SQL_GET_BOXTHEME_BY_PK, BoxTheme.class, uid);
		return b;
	}

	/**
	 * Insert one row.
	 */
	public String insertBoxTheme(DOBoxTheme boxTheme) {
		String uid = IDGenerator.getInstance().genUID();
		boxTheme.setUid(uid);
		dbe.execute(SQL_INSERT_BOXTHEME, boxTheme.getUid(), boxTheme.getName(), boxTheme.getThemePicture(), boxTheme.getThemeMusic(),
				boxTheme.getBgIndex(), boxTheme.getBgDetail(), boxTheme.getBgPannel(), boxTheme.getPictures(),
				boxTheme.getRecommendTypeDsid(), boxTheme.getChannelUid(), boxTheme.getEpChannelUiDsid(), boxTheme.getIsAds(),
				boxTheme.getEndDate(), boxTheme.getDescription());
		return uid;
	}

	/**
	 * Update by PK.
	 */
	public void updateBoxTheme(DOBoxTheme boxTheme) {
		dbe.execute(SQL_UPDATE_BOXTHEME, boxTheme.getName(), boxTheme.getThemePicture(), boxTheme.getThemeMusic(), boxTheme.getBgIndex(),
				boxTheme.getBgDetail(), boxTheme.getBgPannel(), boxTheme.getPictures(), boxTheme.getRecommendTypeDsid(),
				boxTheme.getChannelUid(), boxTheme.getEpChannelUiDsid(), boxTheme.getIsAds(), boxTheme.getEndDate(),
				boxTheme.getDescription(), boxTheme.getUid());
	}

	/**
	 * Delete row by PK.
	 */
	public void deleteBoxTheme(String uid) {
		dbe.execute(SQL_DEL_BOXTHEME, uid);
	}

}